#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QtNetwork/QUdpSocket>
#include<QtNetwork/QNetworkDatagram>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    udp=new QUdpSocket();
    connect(udp,&QUdpSocket::readyRead,this,[=](){
        const QNetworkDatagram& responseDatagram = udp->receiveDatagram();
         QString response = responseDatagram.data();
         ui->listWidget->addItem(QString("server: ") + response);
    });
}

MainWindow::~MainWindow()
{
    delete ui;

}


void MainWindow::on_pushButton_clicked()
{
    QString a=ui->lineEdit->text();
    QNetworkDatagram q(a.toUtf8(),QHostAddress("127.0.0.1"),9090);
    udp->writeDatagram(q);
    ui->listWidget->addItem("client:"+a);
    ui->lineEdit->clear();

}
